home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 1 / Cream of the Crop 1.iso / PROGRAM / CHARTP10.ARJ / PARSE.CPP < prev    next >
C/C++ Source or Header  |  1992-01-26  |  1KB  |  63 lines

  1.  
  2. // Copyright 1992, David Perelman-Hall & Jamshid Afshar
  3.  
  4. #include "misc.h"
  5. #include "edge.h"
  6. #include "chart.h"
  7. #include "agenda.h"
  8. #include "rules.h"
  9.  
  10. #ifdef __TURBOC__
  11. #include <alloc.h>
  12. #endif
  13.  
  14.  
  15. bool parse( const Category& goal, const Category_Sequence& string )
  16. {
  17.    cout << "Parsing \"" << string << "\"";
  18.    cout << endl << endl;
  19.  
  20.    RuleList rules;
  21.  
  22.    // READ IN THE RULES
  23.    rules.read("rulelist");
  24.  
  25.    Agenda agenda;
  26.    Chart chart(string);
  27.    int vertex = 0; 
  28.    Category_Sequence remaining = string;
  29.    
  30.    while( !remaining.isEmpty() ) {
  31.       agenda.add( Edge( vertex, vertex + 1, remaining.pop() ), chart );
  32.       vertex += 1;
  33.    }
  34.  
  35.    while( !agenda.isEmpty() ){
  36.  
  37.       // GRAB AN EDGE OFF THE AGENDA.
  38.       Edge edge = agenda.getNext();
  39.  
  40.       // SHOW THE EDGE
  41.       cout << "Next edge off agenda-: " << edge << "\n";
  42.  
  43.       // ADD EDGE TO CHART. TRY TO COMBINE EDGE W/ OTHERS IN CHART.
  44.       // THEN ADD ANY APPLICATION OF FUNDAMENTAL RULE TO AGENDA.
  45.       // IF EDGE IS INACTIVE, TRY TO APPLY GRAMMAR RULES TO RESULT IN
  46.       // AN APPLICATION OF FUNDAMENTAL RULE--AND ADD ANY APPLICATION TO
  47.       // AGENDA.
  48.       chart.add( edge, agenda, rules );
  49. #ifdef __TURBOC__
  50.       cerr << "Memory left: " << farcoreleft() << endl;
  51. #endif
  52.    }
  53.  
  54.    cout << endl;
  55.    cout << chart;
  56.    cout << endl;
  57.  
  58.    // TEST CHART FOR SUCCESS(ES)
  59.    return chart.success( goal, string );
  60.  
  61.    // will work on parse tree today
  62. }
  63.